<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true"
			:title="'上传隐患'">
		</u-navbar>
		<u-form :model="hiddenDangerForm" ref="hiddenDangerForm" label-width="100px" style="padding: 24rpx;">
			<u-form-item label-position="left" label="隐患名称" prop="name">
				<u-input type="text" :border="border" placeholder="请输入详细的隐患 地点" v-model="hiddenDangerForm.name" />
			</u-form-item>
			<u-form-item label-position="left" label="隐患地点" prop="address">
				<u-input type="text" :border="border" placeholder="请输入详细的隐患 地点" v-model="hiddenDangerForm.address" />
			</u-form-item>
			<u-form-item label-position="left" label="隐患描述" prop="remark">
				<u-input type="text" :border="border" placeholder="请填写具体情况描述" v-model="hiddenDangerForm.remark" />
			</u-form-item>
			<u-form-item label-position="left" label="隐患图片" prop="abnormalPic">
				<u-image v-if="hasUrl" width="50%" height="450rpx"
					:src="hiddenDangerForm.abnormalPic+'?x-oss-process=style/zip_app'" mode="aspectFit">
					<u-loading slot="loading"></u-loading>
				</u-image>
				<u-image v-if="!hasUrl" width="50%" height="450rpx"
					:src="hiddenDangerForm.abnormalPic+'?x-oss-process=style/zip_app'" mode="aspectFit"
					@click="uploadPic">
					<view slot="error" style="font-size: 24rpx;">
						<u-icon name="plus"></u-icon>
					</view>
				</u-image>
			</u-form-item>
		</u-form>
		<u-select v-model="equipmentShow" :default-value="defaultValue" mode="mutil-column-auto" :list="equipmentList"
			value-name="ucId" label-name="name" @confirm="confirm"></u-select>
		<u-button @click="submit" type="primary" style="margin: 24rpx;">生成隐患工单</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				border: true,
				hiddenDangerForm: {
					equipmentName: '',
					remark: "",
					taskId: '',
				},
				src: "http://androidimg/storage/emulated/0/1623736890095.jpeg",
				equipmentList: [],
				equipmentShow: false,
				defaultValue: [],
				ucId: '',
				equipmentId: '',
				mainDataId: '',
				hasUrl:false,
				rules: {
					name: [{
						required: true,
						message: '请输入隐患名称',
						trigger: ['blur'],
					}],
					address: [{
						required: true,
						message: '请输入隐患详细地址',
						trigger: ['blur'],
					}],
					remark: [{
						required: true,
						message: '请输入隐患详细描述',
						trigger: ['blur'],
					}],
					abnormalPic: [{
						required: true,
						message: '请上传隐患照片',
						trigger: ['blur'],
					}]
				}
			}
		},
		onShow() {
			// this.getInMaintenanceInfoVo(this.ucId)
		},
		onLoad(e) {
			this.ucId = e.ucId
			this.equipmentId = e.equipmentId
			this.mainDataId = e.mainDataId
			this.hiddenDangerForm.taskId = e.ucId
			this.hiddenDangerForm.equipmentId = e.equipmentId
			this.hiddenDangerForm.mainDataId = e.mainDataId
		},
		methods: {
			submit() {
				this.$refs.hiddenDangerForm.validate(valid => {
					if (valid) {
						this.utils.request("/api/app/inHiddenDanger/maintenanceGenerateHiddenDanger", this
							.hiddenDangerForm,
							"post", "app", true).then(res => {
							uni.navigateBack({
								delta: 1
							})
						}).catch(error => {
							console.log(error)
						})
					} else {
						console.log('验证失败');
					}
				});

			},
			getInMaintenanceInfoVo(val) {
				this.utils.request("/api/app/maintenanceRecord/getInMaintenanceInfoVo", {
					ucId: val
				}, "post", "app", true).then(res => {
					this.getEquipmentList(res.data.enterpriseId)
				}).catch(error => {
					console.log(error)
				})
			},
			getEquipmentList(val) {
				this.utils.request("/api/app/equipment/getSubfieldEquipmentList", {
					enterpriseId: val
				}, "post", "app", true).then(res => {
					console.log(res.data)
					this.equipmentList = res.data
				}).catch(error => {
					console.log(error)
				})
			},
			confirm(e) {
				e.map((val, index) => {
					this.hiddenDangerForm.equipmentId = val.value
					this.hiddenDangerForm.equipmentName = val.label
				})
			},
			uploadPic() {
				window.native.h5Camera()
				window.native.getUri(res => {
					this.hiddenDangerForm.abnormalPic = res.uri
					this.hasUrl = true
				})
			}
		},
		onReady() {
			this.$refs.hiddenDangerForm.setRules(this.rules);
		},
	}
</script>

<style>

</style>
